<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <table class="layui-table">
            <tr>
                <td style="text-align: center;width: 12%">积分奖励-类型</td>
                <td>
                    <div class="layui-input-inline" style="width: 250px;">
                        <select id="type" name="type" class="layui-input" lay-filter="is_display" style="width: 500px;">
                            <option value="1" <?php if($result['type'] == 1):?>selected<?php endif;?>>商城-订单</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">积分比例（用户）</td>
                <td>
                    <input type="text" name="user_ratio" id="user_ratio" value="<?php echo $result['user_ratio'];?>" lay-verify="required" placeholder="积分比例（用户）" class="layui-input" style="width: 300px;float: left;" onkeyup="num(this)">
                    <span style="float: left;padding-top: 10px;padding-left: 10px;">注释：1元对应 N 积分</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">积分比例（一级推荐）</td>
                <td>
                    <input type="text" name="first_referrer_ratio" id="first_referrer_ratio" value="<?php echo $result['first_referrer_ratio'];?>" lay-verify="required" placeholder="积分比例（一级推荐）" class="layui-input" style="width: 300px;float: left;" onkeyup="num(this)">
                    <span style="float: left;padding-top: 10px;padding-left: 10px;">注释：1元对应 N 积分</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">积分比例（二级推荐）</td>
                <td>
                    <input type="text" name="second_referrer_redio" id="second_referrer_redio" value="<?php echo $result['second_referrer_redio'];?>" lay-verify="required" placeholder="积分比例（二级推荐）" class="layui-input" style="width: 300px;float: left;" onkeyup="num(this)">
                    <span style="float: left;padding-top: 10px;padding-left: 10px;">注释：1元对应 N 积分</span>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="padding-left: 100px;">
                    <input type="hidden" value="<?php echo $result['id'];?>" name="id" id="id">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form'], function () {
            var form = layui.form;
            form.on('submit(*)', function(data){
                $.ajax({
                    url:'{:url("/admin/UserIntegral/add")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;
            });
        });
        //验证只能输入数字
        function num(object) {
            var value   = object.value;
            var id      = object.id;
            if (isNaN(value)){
                layer.msg('请输入正确的数字',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }
    </script>
</block>
